<template>
  <!-- 二级列表 -->
  <div class="classifity-warp">
    <div class="classifity-list">
      <div class="list-nav">
        <span class="el-icon-s-operation">数据列表</span>
        <el-button class="list-btn" @click="addBtn">添加</el-button>
      </div>

      <!-- 列表主要内容 -->
      <div class="list-content">
        <el-table
          ref="multipleTable"
          :data="tableData"
          border
          tooltip-effect="dark"
          style="width: 100%"
        >
          <el-table-column type="selection" width="55"> </el-table-column>
          <el-table-column prop="id" label="商品编号" width="180">
          </el-table-column>
          <el-table-column prop="name" label="品牌名称" width="180">
          </el-table-column>
          <el-table-column prop="level" label="级别" width="180">
          </el-table-column>
          <el-table-column prop="count" label="商品数量" width="180">
          </el-table-column>
          <el-table-column label="设置">
            <template>
              <el-button
                type="text"
                @click="lookSubordinate"
                >查看下级</el-button
              >
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button type="text"  @click="edit(scope.row)"
                >编辑</el-button
              >
              <el-button @click="del(scope.row.id)" type="text" >
                删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页 -->
        <div class="classifity-footer">
          <div class="pag">
            <el-pagination
              background
              layout="prev, pager, next"
              :total="currentCount"
              @current-change="toPage"
            >
            </el-pagination>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  SubordinateApi,
  pageSecond,
  delSecond,
} from "@/http/commodity-management/classityApi";
export default {
  name: "LookSubordinate",
  data() {
    return {
      tableData: [],
      multipleSelection: [],
      current: 1,
      currentCount: 1,
      size: 10,
    };
  },
  methods: {
    del(id) {
      console.log("删除的id：", id);
      this.$confirm("此操作将永久删除该条数据, 是否继续?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          delSecond(id);
          this.renderPag();
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    renderPag(page, size) {
      SubordinateApi()
        .then((res) => {
          this.currentCount = res.data.number;
        })
        .catch((err) => {
          console.log(err);
        });
      pageSecond(page, size)
        .then((res) => {
          this.tableData = res.data.data;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    toPage(curr) {
      this.renderPag(curr, this.size);
    },
    lookSubordinate() {
      //查看下级
      this.$router.push({ path: "/goods/three" });
    },
    addBtn() {
      //新增
      this.$router.push({ path: "/goods/addTwo" });
    },
    edit(row) {
      //编辑
      this.$router.push({ path: "/goods/TwoEdit", query: { obj: row } });
    },
  },
  created() {
    this.renderPag(this.current, this.size);
  },
};
</script>

<style lang="scss" scoped>
@import "@/assets/sass/var.scss";

.classifity-warp {
  padding: 0px;

  span {
    color: #999;
    size: 14px;
    font-weight: 500;
  }
  .nav-right {
    float: right;
    margin-top: 4px;
  }
  .classifity-list {
    background-color: rgba(243, 243, 243);
    border: 1px solid rgb(228, 228, 228);
    margin-top: 20px;

    .list-nav {
      padding: 0 20px;
      line-height: 50px;
      span {
        color: #666;
      }
      .list-btn {
        float: right;
        margin-top: 5px;
      }
    }

    .list-content {
      .classifity-add {
        color: $panel-color;
      }
      .classifity-footer {
        height: 50px;
        padding-top: 0;
        box-sizing: border-box;
        width: 100%;
        border: 1px solid #e4e4e4;

        .pag {
          float: right;
          margin-top: 8px;
        }
      }
      .classifity-footer ::v-deep .active {
        background-color: $panel-color !important;
      }
    }
  }
}
</style>